package com.hqyj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqyj.dao.ScoreMapper;
import com.hqyj.pojo.KaoQin;
import com.hqyj.pojo.Score;
import com.hqyj.pojo.Score;
import com.hqyj.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;

@Service
public class ScoreServiceImpl implements ScoreService {

    @Autowired
    ScoreMapper scoreMapper;
    @Override
    public HashMap<String, Object> selectAll(Score score) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        //1 设置分页参数：页码和条数
        PageHelper.startPage(score.getPage(),score.getRow());
        //2 查询结果集合
        List<Score> list = scoreMapper.selectAll();

        // 3 创建分页对象
        PageInfo<Score> pageInfo = new PageInfo<Score>(list);

        List<Score> listResult = pageInfo.getList();

        map.put("total",pageInfo.getTotal());
        map.put("pages",pageInfo.getPages());
        map.put("endPage",pageInfo.getNavigateLastPage());
        map.put("curPage",score.getPage());
        map.put("data",pageInfo.getList());
        return map;
    }

    @Override
    public HashMap<String, Object> updateByPrimaryKeySelective(Score record) {
        int n =scoreMapper.updateByPrimaryKeySelective(record);
        HashMap<String, Object> map = new HashMap<>();
        map.put("info","修改失败");
        if (n > 0){
            map.put("info","修改成功");
        }

        return map;
    }

    //删除
    @Override
    public HashMap<String, Object> deleteByPrimaryKey(Long scId) {
        int n = scoreMapper.deleteByPrimaryKey(scId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("info","删除失败");
        if (n > 0){
            map.put("info","删除成功");
        }

        return map;
    }


    //添加
    @Override
    public HashMap<String, Object> insertSelective(Score record) {
        int n = scoreMapper.insertSelective(record);
        HashMap<String, Object> map = new HashMap<>();
        map.put("info","新增失败");
        if (n > 0){
            map.put("info","新增成功");
        }

        return map;
    }

}
